import request from '@/utils/request.js'
// import store from '@/store'

/**
 * 添加关注
 */
export const addFollow = userId => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: userId
    }
  })
}

/**
 * 取消关注
 */
export const deleteFollow = userId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${userId}`
  })
}

// 登录接口封装
// data：表单数据
export const login = (data) => {
  // request 就是 axios 创建出来实例，请求后返回值是 Promise 对象
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  })
}

export const sendCode = (mobile) => {
  return request({
    method: 'GET',
    url: `v1_0/sms/codes/${mobile}`
  })
}

export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
    // headers: {
    //   Authorization: `Bearer ${store.state.userToken.token}`
    // }
  })
}

// 刷新 token
export const refreshToken = () => {
  return request({
    method: 'PUT',
    url: '/v1_0/authorizations',
    isRefreshToken: true // 这是不是标准的 axios 配置，而是自定义的配置
  })
}
